﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace HExcelToXML
{
    public partial class FormMain : Form
    {
        private System.String m_paymentExcel;
        private XPaymentExcelToXML m_xPaymentExcelToXml;

        /* ********* Constructor ********** */
        public FormMain()
        {
            InitializeComponent();
            m_xPaymentExcelToXml = new XPaymentExcelToXML();
        }

        /* ********** Load ************ */
        private void FormMain_Load(object sender, EventArgs e)
        {
            //UI Setting

            DataSet myDataSet = new DataSet();
            

        }

        /* 
         *  Click Browse Button
         */ 
        private void buttonBrowse_Click(object sender, EventArgs e)
        {
            DialogResult result = openFileDialogPaymentExcel.ShowDialog();
            if (result == DialogResult.OK)
            {
                textBoxPaymentExcel.Text = openFileDialogPaymentExcel.FileName;
                m_paymentExcel = openFileDialogPaymentExcel.FileName;
                m_xPaymentExcelToXml.setExcelFile(m_paymentExcel);
            }
        }

        /*
         * Click Convert to XML button 
         */
        private void buttonToXML_Click(object sender, EventArgs e)
        {
            // check file
            if (m_paymentExcel != null)
            {
                if (File.Exists(m_paymentExcel))
                {
                    if (m_xPaymentExcelToXml.parseExcel() != 0)
                    {
                        MessageBox.Show("Error: Convert Excel to XML Failed. Please Make Sure Your Excel is in Correct Format", "Error Message",
                            System.Windows.Forms.MessageBoxButtons.OK,
                            System.Windows.Forms.MessageBoxIcon.Error);
                        return;
                    }
                    else
                    {


                        MessageBox.Show("Convert Excel to XML Succeed", "Message",
                            System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
                        

                        // TreeView
                        // DataGridView
                        // Load File Content
                        return;
                    }
                }
                else
                {
                    MessageBox.Show("Error: File does not exist any more", "Error Message",
                        System.Windows.Forms.MessageBoxButtons.OK,
                        System.Windows.Forms.MessageBoxIcon.Error);
                    return;
                }
            }
            else 
            {
                MessageBox.Show("Error: Please Upload Excel File", "Error Message",
                       System.Windows.Forms.MessageBoxButtons.OK,
                       System.Windows.Forms.MessageBoxIcon.Error);
                return;
            }
        } 

        /*
         * 
         */
       

    }
}
